﻿using System;
using System.Data;
using UniMana.Utils.Data;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraBars;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using UniMana.Data;

namespace UniMana.Win.Systems
{
    public partial class FrmUserManager : DevExpress.XtraEditors.XtraForm
    {
        private string m_Rule = UniMana.Utils.Configs.RuleConfig.USER_MANAGER;
        public FrmUserManager()
        {
            if (!SysUtils.CheckAccessByRule(m_Rule))
            {
                XtraMessageBox.Show(UniMana.Utils.Configs.RuleConfig.MESSAGEBOX);
                return;
            }
            InitializeComponent();
            LoadData();
            InitControlEvent();
            
            
        }
        public void LoadData()
        {
            #region Load User and Group

            lueCatalogue_Department.GetData(new DBMain().m_DCReadOnly.Catalogue_Departments);
            if (lueCatalogue_Department.EditValue != null)
            {
                grcUserAndGroup.DataSource = System_UserData.GetByDepartment(int.Parse(lueCatalogue_Department.EditValue.ToString())).ToDataTable();
            }
            else
            {
                grcUserAndGroup.DataSource = System_UserData.GetList().ToDataTable();
            }
            //tltUserAndGroup.DataSource = System_UserData.GetByGroup();
            
            #endregion
        }

        public void GetControls(DataTable dt)
        {
            foreach (DataRow dr in dt.Rows)
            {
                System_RuleInfo sri = new System_RuleInfo(dr["RuleID"].ToString());
                sri.Properties.RuleID = dr["RuleID"].ToString();
                sri.Properties.RuleName = dr["RuleID"].ToString().Substring(3);
                sri.Properties.RuleNameVi = dr["RuleNameVi"].ToString();
                sri.Properties.ParentID = dr["ParentID"].ToString();
                sri.Properties.Level = int.Parse(dr["Level"].ToString());
                sri.Properties.Description = "";
                sri.Properties.Owner = "Quản Lý Đào Tạo";
                sri.Save();
            }
        }


        public void DelegateUser(System_UserInfo sui)
        {
            
            DataTable dt = grcUserAndGroup.DataSource as DataTable;
            #region Tạo cấu trúc DataTable dt chứa thông tin user
            if (dt.Columns.Count == 0)
            {
                dt.Columns.Add("System_UserKey");
                dt.Columns.Add("UserName");
                dt.Columns.Add("FullName");
                dt.Columns.Add("Description");
                dt.Columns.Add("Catalogue_DepartmentKey");
                dt.Columns.Add("DateLogined");

            }
            #endregion
            DataRow dRow= (from DataRow dr in dt.Rows where dr["System_UserKey"].ToString().ToUpper() == sui.Properties.System_UserKey.ToString().ToUpper() select dr).FirstOrDefault();
            if (dRow != null)
            {

                dRow["System_UserKey"] = sui.Properties.System_UserKey;
                dRow["UserName"] = sui.Properties.UserName;
                dRow["FullName"] = sui.Properties.FullName;
                dRow["Description"] = sui.Properties.Description;
                //dRow["Catalogue_DepartmentKey"] = sui.Properties.Catalogue_DepartmentKey;
                if (sui.Properties.DateLogined != null)
                {
                    dRow["DateLogined"] = sui.Properties.DateLogined;
                }
            }
            else
            {
                DataRow dr = dt.NewRow();
                dr["System_UserKey"] = sui.Properties.System_UserKey;
                dr["UserName"] = sui.Properties.UserName;
                dr["FullName"] = sui.Properties.FullName;
                dr["Description"] = sui.Properties.Description;
                //dr["Catalogue_DepartmentKey"] = sui.Properties.Catalogue_DepartmentKey;
                dr["DateLogined"] = DBNull.Value;
                dt.Rows.Add(dr);
            }
        }

        //public void DelegateGroup(DataRow[] dr)
        //{
        //    DataTable dt = grcInfoUserAndGroup.DataSource as DataTable;
        //    if (dt.Columns.Count == 0)
        //    {
        //        dt.Columns.Add("System_GroupKey");
        //        dt.Columns.Add("Name");
        //        dt.Columns.Add("ParentName");
        //        dt.Columns.Add("Description");
        //    }
            
        //    for(int i=0 ;i< dr.Length;i++)
        //    {
        //        //DataRow drNew = dt.NewRow();
        //        //drNew = dr[i];
        //        dt.Rows.Add(new object[] { dr[i][0], dr[i][1], dr[i][2], dr[i][3] });
        //        DataTable dtGr = System_Group_RuleData.GetByGroup(Convert.ToInt16(dr[i][0])).ToDataTable();
        //        foreach (DataRow row in dtGr.Rows)
        //        {
        //            Guid ruleKey = Guid.Parse(row["System_RuleKey"].ToString());
        //            System_User_RuleInfo suri = new System_User_RuleInfo(Guid.Parse(tltUserAndGroup.Selection[0].GetValue("ID").ToString()), ruleKey);
        //            suri.Properties.AllowAccess = true;
        //            suri.Properties.AllowAdd = true;
        //            suri.Properties.AllowDelete = true;
        //            suri.Properties.AllowEdit = true;
        //            suri.Properties.AllowExport = true;
        //            suri.Properties.AllowImport = true;
        //            suri.Properties.AllowPrint = true;
        //            suri.Properties.AllowSave = true;

        //            suri.Save();
        //        }
        //    }

            //dtSystem_User_Rule = System_User_RuleData.GetRuleByUser(tltUserAndGroup.Selection[0].GetValue("DescName").ToString()).ToDataTable();
           // tltPermission.DataSource = dtSystem_User_Rule;
        //}

        #region Khởi tạo XucBar
        public void InitControlEvent()
        {
            //xucBar1.AddNewVisible = false;
            //xucBar1.EditVisible = false;
            //xucBar1.DeleteVisible = false;
            //xucBar1.ExportExcelVisible = false;
            //xucBar1.ImportExcelVisible = false;

            //BarButtonItem btnLoad = new BarButtonItem();
            //btnLoad.Caption= "Tải dữ liệu";
            //xucBar1.Controls.Add(btnLoad);
            //xucBar1.btnSave_Click += new Controls.xucBar.ButtonClickHandler(btnSave_Click);
            xucBar1.btnAddNew_Click += new Utils.Controls.xucBar.ButtonClickHandler(btnAddNew_Click);
            xucBar1.btnDelete_Click += new Utils.Controls.xucBar.ButtonClickHandler(btnDelete_Click);
            //if (UniMana.Lib.Sys.Utils.CheckEditByRule("test1"))
            //{
            xucBar1.btnEdit_Click += new Utils.Controls.xucBar.ButtonClickHandler(btnEdit_Click);
            //}
             //else
             //{
             //    MessageBox.Show("Bạn không có quyền chỉnh sửa thông tin người dùng", "Thông báo");
             //}
        }

        private void btnEdit_Click(object sender, ItemClickEventArgs e)
        {
            if (!SysUtils.CheckEditByRule(m_Rule))
            {
                XtraMessageBox.Show(UniMana.Utils.Configs.RuleConfig.MESSAGEBOX);
                xucBar1.dlg.Close();
                return;
            }
                if (grvSystem_User.GetFocusedRow() != null)
                {
                    System_UserInfo sui = new System_UserInfo(grvSystem_User.GetFocusedRowCellValue("UserName").ToString());
                    FrmUserManager_SubCreateUser f = new FrmUserManager_SubCreateUser(sui);
                    f.passData = new FrmUserManager_SubCreateUser.PassData(DelegateUser);
                    f.Text = "Sửa thông tin người dùng: " + grvSystem_User.GetFocusedRowCellValue("UserName").ToString();
                    xucBar1.dlg.Close();
                    f.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
                    f.ShowDialog();
                }
            

        }

        private void btnAddNew_Click(object sender, ItemClickEventArgs e)
        {
            if (!SysUtils.CheckAddByRule(m_Rule))
            {
                XtraMessageBox.Show(UniMana.Utils.Configs.RuleConfig.MESSAGEBOX);
                xucBar1.dlg.Close();
                return;
            }
            //System_UserInfo sui = new System_UserInfo();
            FrmUserManager_SubCreateUser f = new FrmUserManager_SubCreateUser();
            f.passData = new FrmUserManager_SubCreateUser.PassData(DelegateUser);
            f.Text = "Thêm mới người dùng";
            xucBar1.dlg.Close();
            f.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
            f.ShowDialog();

        }

        private void btnDelete_Click(object sender, ItemClickEventArgs e)
        {
            if (!SysUtils.CheckDeleteByRule(m_Rule))
            {
                XtraMessageBox.Show(UniMana.Utils.Configs.RuleConfig.MESSAGEBOX);
                xucBar1.dlg.Close();
                return;
            }

            xucBar1.dlg.Close();
            DialogResult dagResult = MessageBox.Show("Bạn thật sự muốn xóa nhóm khỏi hệ thống", "Thông báo", MessageBoxButtons.OKCancel);
            if (dagResult == DialogResult.Cancel)
            {
                return;
            }

            System_UserInfo sui = new System_UserInfo(Guid.Parse(grvSystem_User.GetFocusedRowCellValue("System_UserKey").ToString()));
            IQueryable<System_Group> iq = System_GroupData.GetGroupByUserKey(new DBMain(),sui.Properties.System_UserKey);
            foreach (var r in iq)
            {
                System_User_GroupInfo sugi = new System_User_GroupInfo(sui.Properties.System_UserKey, r.System_GroupKey);
                sugi.Delete();
                sugi.Save();
            }
            IQueryable<System_User_Rule> surs = System_User_RuleData.GetSystemUserRuleByUser(sui.Properties.System_UserKey);
            
            foreach( var r in surs)
            {
                System_User_RuleInfo suri = new System_User_RuleInfo(r.System_UserKey, r.System_RuleKey);
                suri.Delete();
                suri.Save();
            }

            DataTable dt_srds = System_Rule_DepartmentData.GetAllowByUserKey(new DBMain(), sui.Properties.System_UserKey).ToDataTable();
            if(dt_srds!=null)
            {
                foreach(DataRow dr in dt_srds.Rows)
                {
                    System_Rule_DepartmentInfo srdi = new System_Rule_DepartmentInfo(sui.Properties.System_UserKey, int.Parse(dr["Catalogue_DepartmentKey"].ToString()));
                    srdi.Delete();
                    srdi.Save();
                }
            }
             

            sui.Delete();
            sui.Save();
            grvSystem_User.DeleteSelectedRows();
        }

        //private void btnSave_Click(object sender, ItemClickEventArgs e)
        //{
        //    xucBar1.dlg.Close();
        //    this.Validate();
        //    foreach (DataRow dr in dtSystem_User_Rule.GetChanges().Rows)
        //    {
        //        System_User_RuleInfo suri = new System_User_RuleInfo(Guid.Parse(dr["System_UserKey"].ToString()), Guid.Parse(dr["System_RuleKey"].ToString()));

        //        if (dr["AllowAccess"] != DBNull.Value)
        //            suri.Properties.AllowAccess = Convert.ToBoolean(dr["AllowAccess"]);
        //        if (dr["AllowAdd"] != DBNull.Value)
        //            suri.Properties.AllowAdd = Convert.ToBoolean(dr["AllowAdd"]);
        //        if (dr["AllowDelete"] != DBNull.Value)
        //            suri.Properties.AllowDelete = Convert.ToBoolean(dr["AllowDelete"]);
        //        if (dr["AllowEdit"] != DBNull.Value)
        //            suri.Properties.AllowEdit = Convert.ToBoolean(dr["AllowEdit"]);
        //        if (dr["AllowExport"] != DBNull.Value)
        //            suri.Properties.AllowExport = Convert.ToBoolean(dr["AllowExport"]);
        //        if (dr["AllowImport"] != DBNull.Value)
        //            suri.Properties.AllowImport = Convert.ToBoolean(dr["AllowImport"]);
        //        if (dr["AllowPrint"] != DBNull.Value)
        //            suri.Properties.AllowPrint = Convert.ToBoolean(dr["AllowPrint"]);
        //        if (dr["AllowSave"] != DBNull.Value)
        //            suri.Properties.AllowSave = Convert.ToBoolean(dr["AllowSave"]);

        //        suri.Save();
        //    }

        //}
        #endregion
       

        //private void tltUserAndGroup_FocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e)
        //{
        //    if (e.Node == null) return;
        //    if (e.Node != null && e.Node.Level == 1)
        //    {
        //        string TreeID = Convert.ToString(e.Node.GetValue(colUserName) ?? "");
        //        DataTable tb_group = new DataTable();
        //        //tb_group = System_GroupData.GetGroupByUserKey(new DBMain(), TreeID).ToDataTable();
        //        grcInfoUserAndGroup.DataSource = tb_group;

        //        //dtSystem_User_Rule = System_User_RuleData.GetRuleByUser(TreeID).ToDataTable();
        //        //tltPermission.DataSource = dtSystem_User_Rule;
        //    }

        //    if (e.Node.Level == 0)
        //    {
        //        (grcInfoUserAndGroup.DataSource as DataTable).Clear();
        //        dtSystem_User_Rule.Clear();
        //       // tltPermission.DataSource = null;
        //    }


        //}

        
        private void lueCatalogue_Department_EditValueChanged(object sender, EventArgs e)
        {
            if (lueCatalogue_Department.EditValue != null)
            {
                grcUserAndGroup.DataSource = System_UserData.GetByDepartment(int.Parse(lueCatalogue_Department.EditValue.ToString())).ToDataTable();
            }
        }

        private void grvSystem_User_DoubleClick(object sender, EventArgs e)
        {
            if (grvSystem_User.GetFocusedRow() != null)
            {
                System_UserInfo sui = new System_UserInfo(grvSystem_User.GetFocusedRowCellValue("UserName").ToString());
                FrmUserManager_SubCreateUser f = new FrmUserManager_SubCreateUser(sui);
                f.passData = new FrmUserManager_SubCreateUser.PassData(DelegateUser);

                f.Text = "Xem thông tin người dùng: " + grvSystem_User.GetFocusedRowCellValue("UserName").ToString();

                f.btnAddGroup.Enabled = false;
                f.btnRemoveGroup.Enabled = false;
                f.btnSaveAndAdd.Enabled = false;
                f.btnSaveAndClose.Enabled = false;
                f.btnAddPerData.Enabled = false;
                f.btnRemovePerData.Enabled = false;

                f.lciPasswordConfirm.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
                f.lciPassword.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
                f.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
                f.ShowDialog();
            }

        }

        //private void btnAddGroup_Click(object sender, EventArgs e)
        //{
        //    if (tltUserAndGroup.Selection[0].Level != 0)
        //    {
        //        FrmGroupList f = new FrmGroupList(Guid.Parse(tltUserAndGroup.Selection[0].GetValue("ID").ToString()));
        //        f.passData = new FrmGroupList.PassData(DelegateGroup);
        //        f.ShowDialog();
        //    }
        //}

        //private void btnRemoveGroup_Click(object sender, EventArgs e)
        //{
        //    //try
        //    //{
        //    //    DataTable dtGr = System_Group_RuleData.GetByGroup(int.Parse(grvMain.GetFocusedRowCellValue("System_GroupKey").ToString())).ToDataTable();
                
        //    //    foreach (DataRow row in dtGr.Rows)
        //    //    {
        //    //        Guid ruleKey = Guid.Parse(row["System_RuleKey"].ToString());
        //    //        System_User_RuleInfo suri = new System_User_RuleInfo(Guid.Parse(tltUserAndGroup.Selection[0].GetValue("ID").ToString()), ruleKey);
        //    //        suri.Delete();
        //    //        suri.Save();
        //    //    }

        //    //    System_User_GroupInfo sugi = new System_User_GroupInfo(Guid.Parse(tltUserAndGroup.Selection[0].GetValue("ID").ToString()), int.Parse(grvMain.GetFocusedRowCellValue("System_GroupKey").ToString())); 
        //    //    sugi.Delete();
        //    //    sugi.Save();
        //    //    grvMain.DeleteSelectedRows();
        //    //    //dtSystem_User_Rule = System_User_RuleData.GetRuleByUser(tltUserAndGroup.Selection[0].GetValue("DescName").ToString()).ToDataTable();
        //    //    //tltPermission.DataSource = dtSystem_User_Rule;
        //    //}
        //    //catch { }
        //}

        //private void tltUserAndGroup_FocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e)
        //{
        //    if (e.Node == null) return;
        //    if (e.Node != null && e.Node.Level == 0 || e.Node != null && e.Node.Level == 1)
        //    {
        //        #region
        //        string TreeID = Convert.ToString(e.Node.GetValue(colPARENT_ID) ?? "");
        //        System.Data.DataSet ds;
        //        ds = new System.Data.DataSet();
        //        DataTable tb_group = new DataTable("Groups");
        //        DataTable tb_user = new DataTable("Users");
                
        //        tb_group = Catalogue_DepartmentData.GetByKey(int.Parse(TreeID)).ToDataTable();
        //        tb_user = System_UserData.GetByDepartment(int.Parse(TreeID)).ToDataTable();
                
        //        ds.Tables.Add(tb_group);
        //        ds.Tables.Add(tb_user);

        //        DataColumn keycolumn = tb_group.Columns["Catalogue_DepartmentKey"];
        //        DataColumn keyforeigncolumn = tb_user.Columns["Catalogue_DepartmentKey"];

        //        ds.Relations.Add("GroupUser", keycolumn, keyforeigncolumn);

        //        grcInfoUserAndGroup.DataSource = ds.Tables["table1"];
        //        grcInfoUserAndGroup.ForceInitialize();

        //        grvInfoUserAndGroup = new GridView(grcInfoUserAndGroup);
        //        grcInfoUserAndGroup.LevelTree.Nodes.Add("GroupUser", grvInfoUserAndGroup);
        //        grvInfoUserAndGroup.PopulateColumns(ds.Tables["table2"]);

        //        //grvMain.Columns["Name"].VisibleIndex = -1;

        //        grvInfoUserAndGroup.Columns["Catalogue_DepartmentKey"].VisibleIndex = -1;
        //        grvInfoUserAndGroup.Columns["System_UserKey"].VisibleIndex = -1;
        //        ListGroup_Init(grvMain);

        //        #endregion
        //        #region
        //        {
        //            ListUser_Init(grvInfoUserAndGroup);

        //            grvMain.ExpandMasterRow(0);
        //            StyleFormatCondition condition1 = new DevExpress.XtraGrid.StyleFormatCondition();
        //            condition1.Appearance.BackColor = Color.Khaki;
        //            condition1.Appearance.Options.UseBackColor = true;
        //            condition1.Condition = FormatConditionEnum.Expression;

        //            if (e.Node.Level == 1)
        //            {
        //                string userid = Convert.ToString(e.Node.GetValue(colID) ?? "");
        //                condition1.Expression = "[User_ID] == " + "'" + userid + "'";
        //                grvInfoUserAndGroup.FormatConditions.Add(condition1);
        //                grvMain.FormatConditions.Clear();
        //                grvInfoUserAndGroup.OptionsView.EnableAppearanceEvenRow = true;
        //            }

        //            if (e.Node.Level == 0)
        //            {
        //                condition1.Expression = "[Group_ID] == " + "'" + TreeID + "'";
        //                grvMain.FormatConditions.Add(condition1);
        //            }
        //        }
        //        #endregion


        //        //Permision(TreeID);
        //    }
        //}
        //protected void ListGroup_Init(DevExpress.XtraGrid.Views.Grid.GridView dt)
        //{
        //    dt.OptionsSelection.EnableAppearanceFocusedCell = false;
        //    dt.OptionsSelection.EnableAppearanceFocusedRow = false;
        //    //dt.ViewCaption = "Thông Tin Nhóm";
        //    dt.OptionsDetail.ShowDetailTabs = false;
        //    for (int i = 0; i < dt.Columns.Count; i++)
        //    {
        //        switch (dt.Columns[i].FieldName)
        //        {
        //            case "Group_ID":
        //                dt.Columns[i].OptionsColumn.ReadOnly = true;
        //                dt.Columns[i].OptionsColumn.AllowEdit = false;
        //                dt.Columns[i].OptionsColumn.AllowGroup = DevExpress.Utils.DefaultBoolean.False;
        //                dt.Columns[i].OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False;
        //                dt.Columns[i].OptionsColumn.FixedWidth = true;
        //                dt.Columns[i].Caption = "Mã Nhóm";
        //                dt.Columns[i].Width = 90;
        //                break;
        //            case "Name":
        //                dt.Columns[i].OptionsColumn.ReadOnly = true;
        //                dt.Columns[i].OptionsColumn.AllowEdit = false;
        //                dt.Columns[i].OptionsColumn.AllowGroup = DevExpress.Utils.DefaultBoolean.False;
        //                dt.Columns[i].OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False;
        //                dt.Columns[i].OptionsColumn.FixedWidth = true;
        //                dt.Columns[i].Caption = "Phòng ban";
                      
        //                dt.Columns[i].Width = 180;
        //                break;

        //            case "Description":
        //                dt.Columns[i].OptionsColumn.ReadOnly = true;
        //                dt.Columns[i].OptionsColumn.AllowEdit = false;
        //                dt.Columns[i].OptionsColumn.AllowGroup = DevExpress.Utils.DefaultBoolean.False;
        //                dt.Columns[i].OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False;
        //                dt.Columns[i].OptionsColumn.FixedWidth = true;
        //                dt.Columns[i].DisplayFormat.FormatType = DevExpress.Utils.FormatType.Custom;

        //                dt.Columns[i].Caption = "Diễn Giải";
        //                dt.Columns[i].Width = 180;
        //                break;

        //            case "Active":
        //                dt.Columns[i].OptionsColumn.ReadOnly = true;
        //                dt.Columns[i].OptionsColumn.AllowEdit = false;
        //                dt.Columns[i].OptionsColumn.AllowGroup = DevExpress.Utils.DefaultBoolean.False;
        //                dt.Columns[i].OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False;
        //                dt.Columns[i].OptionsColumn.FixedWidth = true;
        //                dt.Columns[i].Caption = "Kích Hoạt";
        //                dt.Columns[i].Width = 80;
        //                break;
        //            default:
        //                dt.Columns[i].Visible = false;
        //                break;
        //        }
        //    }
        //}
        //protected void ListUser_Init(DevExpress.XtraGrid.Views.Grid.GridView dt)
        //{
        //    dt.OptionsView.ShowAutoFilterRow = true;
        //    dt.OptionsView.ShowGroupPanel = false;
        //    dt.OptionsSelection.EnableAppearanceFocusedCell = false;
        //    dt.OptionsSelection.EnableAppearanceFocusedRow = false;
        //    //dt.ViewCaption = "Thông Tin Người Dùng";

        //    for (int i = 0; i < dt.Columns.Count; i++)
        //    {
        //        switch (dt.Columns[i].FieldName)
        //        {
        //            case "UserID":
        //                dt.Columns[i].OptionsColumn.ReadOnly = true;
        //                dt.Columns[i].OptionsColumn.AllowEdit = false;
        //                dt.Columns[i].OptionsColumn.AllowGroup = DevExpress.Utils.DefaultBoolean.False;
        //                dt.Columns[i].OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False;
        //                dt.Columns[i].OptionsColumn.FixedWidth = false;
        //                dt.Columns[i].Caption = "Mã";
        //                dt.Columns[i].Width = 90;
        //                dt.Columns[i].Visible = false;
        //                break;
        //            case "UserName":
        //                dt.Columns[i].OptionsColumn.ReadOnly = true;
        //                dt.Columns[i].OptionsColumn.AllowEdit = false;
        //                dt.Columns[i].OptionsColumn.AllowGroup = DevExpress.Utils.DefaultBoolean.False;
        //                dt.Columns[i].OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False;
        //                dt.Columns[i].OptionsColumn.FixedWidth = true;
        //                dt.Columns[i].Caption = "Tên Đăng Nhập";
        //                dt.Columns[i].Width = 180;
        //                break;
        //            case "Role_Name":
        //                dt.Columns[i].OptionsColumn.ReadOnly = true;
        //                dt.Columns[i].OptionsColumn.AllowEdit = false;
        //                dt.Columns[i].OptionsColumn.AllowGroup = DevExpress.Utils.DefaultBoolean.False;
        //                dt.Columns[i].OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False;
        //                dt.Columns[i].OptionsColumn.FixedWidth = true;
        //                dt.Columns[i].Caption = "Vai Trò";
        //                dt.Columns[i].Width = 180;
        //                break;
        //            case "Description":
        //                dt.Columns[i].OptionsColumn.ReadOnly = true;
        //                dt.Columns[i].OptionsColumn.AllowEdit = false;
        //                dt.Columns[i].OptionsColumn.AllowGroup = DevExpress.Utils.DefaultBoolean.False;
        //                dt.Columns[i].OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False;
        //                dt.Columns[i].OptionsColumn.FixedWidth = true;
        //                dt.Columns[i].DisplayFormat.FormatType = DevExpress.Utils.FormatType.Custom;
                        
        //                dt.Columns[i].Caption = "Diễn giải";
        //                dt.Columns[i].Width = 180;
        //                break;

        //            case "Active":
        //                dt.Columns[i].OptionsColumn.ReadOnly = true;
        //                dt.Columns[i].OptionsColumn.AllowEdit = false;
        //                dt.Columns[i].OptionsColumn.AllowGroup = DevExpress.Utils.DefaultBoolean.False;
        //                dt.Columns[i].OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False;
        //                dt.Columns[i].OptionsColumn.FixedWidth = true;
        //                dt.Columns[i].Caption = "Kích Hoạt";
        //                dt.Columns[i].Width = 80;
        //                break;
        //            default:
        //                dt.Columns[i].Visible = false;
        //                break;
        //        }
        //    }
        //}

      
    }
}